home *** CD-ROM | disk | FTP | other *** search
- /*
- CDSearchTrack - An XCMD to search to an audio track.
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/10/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDSearchTrack.c
- link -sn Main=CDSearchTrack -sn STDIO=CDSearchTrack ∂
- -sn INTENV=CDSearchTrack -rt XFCN=42 ∂
- -m CDSEARCHTRACK CDSearchTrack.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- void ExtractTrackNo(char *, short *);
- OSErr ASearch(XCmdBlockPtr, short, short, short);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDSearchTrack
- *
- * Purpose: search to a specific an audio track
- *
- * Returns: result of driver call to Search track
- * normally 0, but could have parameter error or
- * other error if non-existent track is specified
- *
- * Side Effects:
- *
- * Description: We need two parameters, the play/pause flag and the
- * track number. Extract the track number and search
- * to it. Play if the play/pause flag tells you to.
- *
- ************************************************************************/
- pascal void
- CDSearchTrack(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short trackNumber;
- short ioRefNum;
- Handle refHandle;
- short flag;
-
- /* Must be two parameters */
- if ((paramPtr->paramCount) != 2)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- /* First param is play/pause flag. Convert it to a short */
- flag = atoi(*(paramPtr->params[0]));
-
- /* Second param is track number. Convert it to a BCD number */
- ExtractTrackNo((char *)*(paramPtr->params[1]), &trackNumber);
-
- result = ASearch(paramPtr, ioRefNum, flag, trackNumber);
-
- /* Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
- /************************************************************************
- *
- * Function: ExtractTrackNo
- *
- * Purpose: Extract track number in BCD from PString
- *
- * Returns: nothing
- *
- * Side Effects: *track gets a new value
- *
- * Description: Extract track number in BCD from Cstring "name".
- * "name" is always of the form "XX", where XX
- * ranges from "1" to "99"
- * (You can't have more than 99 tracks on a compact disc.
- * Bet you didn't know that, did you? Right in the "Yellow
- * Book" specification of compact disc encoding.)
- *
- ************************************************************************/
- void
- ExtractTrackNo(name, track)
- char *name;
- short *track;
- {
- short t;
-
- t = 0;
- while (*name != 0)
- {
- t *= 16;
- t += *name - '0';
- name++;
- }
-
- *track = t;
- }
-
- /************************************************************************
- *
- * Function: ASearch
- *
- * Purpose: start Searching an audio track
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: starts search.
- *
- * Description: The track that you pass in is the location to which
- * you want to search. You can then start play with
- * a pause command.
- *
- ************************************************************************/
- OSErr
- ASearch(paramPtr, refNum, flag, track)
- XCmdBlockPtr paramPtr;
- short refNum;
- short flag; /* 0 = search & pause, 1 = search & play */
- short track; /* track number to search to */
- {
- CDParam myPB;
- short playMode;
- Handle refHandle;
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, PLAYMODE);
- playMode = atoi(*(refHandle));
- DisposHandle(refHandle);
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = ASEARCH;
-
- myPB.csParam[0] = 0;
- myPB.csParam[1] = TRACKADDR;
- myPB.csParam[2] = 0;
- myPB.csParam[3] = 0;
- myPB.csParam[4] = 0;
- myPB.csParam[5] = track;
- myPB.csParam[6] = 0;
- myPB.csParam[7] = flag;
- myPB.csParam[8] = 0;
- myPB.csParam[9] = playMode;
- return (PBControl(&myPB, false));
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-